package MainTest;

import java.util.Stack;

/**
 * Created by xuyi on 2017/2/8.
 */
public class QueueByStack {

    Stack<Integer> stack1 = new Stack<Integer>();
    Stack<Integer> stack2 = new Stack<Integer>();

    public  void push(int node) {
        stack1.add(node);
    }

    public int pop() {
        int target;
        while (!stack1.isEmpty()) {
            stack2.add(stack1.pop());
        }
        target = stack2.pop();
        while (!stack2.isEmpty()) {
            stack1.add(stack2.pop());
        }
        return target;
    }
    public static void main(String[] args) {

        Stack<Integer> stack3 = new Stack<Integer>();
        Stack<Integer> stack4 = new Stack<Integer>();
        stack3.add(1);
        stack3.add(2);
        stack4.addAll(stack3);
        Integer pop = stack4.pop();
        System.out.println(pop);
        stack4.clear();
        stack4.pop();

        System.out.println(stack4);

    }




}
